<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>boost搜索引擎</title>
    <style>
        :root {
            --primary-color: #1a73e8;
            --background-color: #f8f9fa;
            --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        body {
            font-family: 'Segoe UI', Arial, sans-serif;
            margin: 0;
            padding: 2rem;
            background-color: var(--background-color);
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
        }

        .search-box {
            text-align: center;
            margin-bottom: 2rem;
        }

        .search-form {
            position: relative;
            max-width: 600px;
            margin: 0 auto;
            display: flex;
        }

        #search-input {
            width: 100%;
            padding: 1rem 7rem 1rem 2rem;
            font-size: 1.1rem;
            border: 2px solid #dfe1e5;
            border-radius: 2rem;
            outline: none;
            transition: all 0.3s ease;
        }

        #search-input:focus {
            border-color: var(--primary-color);
            box-shadow: var(--card-shadow);
        }

        #search-button {
            position: absolute;
            right: 0.5rem;
            top: 50%;
            transform: translateY(-50%);
            background: var(--primary-color);
            color: white;
            border: none;
            padding: 0.6rem 1.8rem;
            border-radius: 1.5rem;
            cursor: pointer;
            font-weight: 500;
            transition: background 0.3s ease;
        }

        #search-button:hover {
            background: #1557b0;
        }

        .results-container {
            margin-top: 2rem;
        }

        .result-card {
            background: white;
            padding: 1.5rem;
            border-radius: 1rem;
            margin-bottom: 1rem;
            box-shadow: var(--card-shadow);
            transition: transform 0.2s ease;
        }

        .result-card:hover {
            transform: translateY(-2px);
        }

        .result-title {
            color: var(--primary-color);
            font-size: 1.2rem;
            margin-bottom: 0.3rem;
            text-decoration: none;
            display: block;
        }

        .result-desc {
            color: #555;
            line-height: 1.6;
            font-size: 0.95rem;
            margin-bottom: 0.5rem;
        }

        .result-url {
            color: #006621;
            font-size: 0.85rem;
            word-break: break-all;
        }

        .loading {
            text-align: center;
            padding: 2rem;
            display: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="search-box">
            <form class="search-form" id="searchForm">
                <input 
                    type="text" 
                    id="search-input"
                    placeholder="请输入搜索关键词..."
                    autocomplete="off"
                    autofocus
                >
                <button type="submit" id="search-button">搜索一下</button>
            </form>
        </div>

        <div class="loading" id="loading">搜索中...</div>
        <div class="results-container" id="results"></div>
    </div>

    <script>
        const API_ENDPOINT = 'http://192.168.124.7:8080/s?word=';
        
        document.getElementById('searchForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            const query = document.getElementById('search-input').value.trim();
            
            if (!query) {
                alert('请输入搜索内容');
                return;
            }

            try {
                document.getElementById('loading').style.display = 'block';
                document.getElementById('results').innerHTML = '';

                const response = await fetch(`${API_ENDPOINT}${encodeURIComponent(query)}`);
                if (!response.ok) throw new Error(`请求失败: ${response.status}`);
                
                const data = await response.json();
                console.log('搜索结果:', data);

                if (data.length > 0) {
                    const resultsHTML = data.map(result => `
                        <div class="result-card">
                            <a href="${result.url}" class="result-title" target="_blank">
                                ${result.title}
                            </a>
                            <p class="result-desc">${result.desc}</p>
                            <div class="result-url">${result.url}</div>
                        </div>
                    `).join('');
                    document.getElementById('results').innerHTML = resultsHTML;
                } else {
                    document.getElementById('results').innerHTML = `
                        <div class="result-card">
                            <p>未找到相关结果</p>
                        </div>
                    `;
                }
            } catch (error) {
                console.error('搜索出错:', error);
                document.getElementById('results').innerHTML = `
                    <div class="result-card">
                        <p style="color: red">搜索失败：${error.message}</p>
                    </div>
                `;
            } finally {
                document.getElementById('loading').style.display = 'none';
            }
        });
    </script>
</body>
</html>